package WrittenTest;

import java.util.Arrays;
import java.util.Scanner;

public class test7 {
    // 输入整数n，判断最少需要多少步把它变成斐波那契数列
    // 算法原理：滑动窗口
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a, b = 0, c = 1;
        // 当c>n时，此时n在b和c之间
        while (c < n) {
            a = b;
            b = c;
            c = a + b;
        }
        // 利用min()求得最小值
        int min = Math.min(c - n, n - b);
        System.out.println(min);
    }
}
